﻿using System;
using System.Collections.Generic;

namespace FFACETools
{
    public partial class FFACE
    {
        /// <summary>
        /// Class container for position of NPC
        /// </summary>
        public class Position
        {
            #region Members

            /// <summary>
            /// X position of NPC
            /// </summary>
            public float X { get; set; }

            /// <summary>
            /// Y position of NPC
            /// </summary>
            public float Y { get; set; }

            /// <summary>
            /// Z position of NPC
            /// </summary>
            public float Z { get; set; }

            /// <summary>
            /// Heading of NPC
            /// </summary>
            public float H { get; set; }

            #endregion

            #region Methods

            /// <summary>
            /// Determines if the current Position is equal to the passed position
            /// </summary>
            public override bool Equals(object obj)
            {
                bool bResult = false;

                if (obj is Position)
                {
                    if (X.Equals(((Position)obj).X)
                        && Y.Equals(((Position)obj).Y)
                        && Z.Equals(((Position)obj).Z)
                        && H.Equals(((Position)obj).H))
                        bResult = true;
                }

                return bResult;

            } // @ public override bool Equals(object obj)

            /// <summary>
            /// Serves as a hash function for a particular type.
            /// </summary>
            public override int GetHashCode()
            {
                return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + H.GetHashCode();

            } // @ public override int GetHashCode()

            #endregion

        } // @ public class Position

        /// <summary>
        /// Wrapper class for NPC information from FFACE
        /// </summary>
        public class NPCTools
        {
            #region Constructor

            /// <summary>
            /// Constructor
            /// </summary>
            /// <param name="instanceID">Instance ID generated from FFACE</param>
            /// <param name="index">Index of the NPC</param>
            public NPCTools(int instanceID)
            {
                _InstanceID = instanceID;

            } // @ public NPCWrapper(int instanceID)

            #endregion

            #region Members

            /// <summary>
            /// Instance ID generated by FFACE
            /// </summary>
            private int _InstanceID { get; set; }

            #endregion

            #region Methods

            /// <summary>
            /// If the NPC is rendered on the screen
            /// </summary>
            public byte NPCBit(short id)
            {
                return GetNPCBit(_InstanceID, id);

            } // @ public byte NPCBit(int index)

            /// <summary>
            /// Type of NPC
            /// </summary>
            public NPCType NPCType(short id)
            {
                return GetNPCType(_InstanceID, id);

            } // @ public byte NPCType

            /// <summary>
            /// Whether the NPC is claimed or not
            /// </summary>
            public bool IsClaimed(short id)
            {
                return IsNPCclaimed(_InstanceID, id);

            } // @ public bool IsClaimed

            /// <summary>
            /// Server ID of the person who first claimed the mob
            /// </summary>
            public int ClaimedID(short id)
            {
                return GetNPCclaimID(_InstanceID, id);

            } // @ public bool ClaimedID

            /// <summary>
            /// Whether the NPC is active or not
            /// </summary>
            public bool IsActive(short id)
            {
                return NPCIsActive(_InstanceID, id);

            } // @ public bool IsActive

            /// <summary>
            /// Name of the NPC
            /// </summary>
            public string Name(short id)
            {
                    int size = 20;
                    byte[] buffer = new byte[size];
                    GetNPCName(_InstanceID, id, buffer, ref size);

                    return System.Text.Encoding.ASCII.GetString(buffer, 0, size - 1);

            } // @ public bool Name

            /// <summary>
            /// X position of the NPC
            /// </summary>
            public float PosX(short id)
            {
                return GetNPCPosX(_InstanceID, id);

            } // @ public double PosX

            /// <summary>
            /// Y position of the NPC
            /// </summary>
            public float PosY(short id)
            {
                return GetNPCPosY(_InstanceID, id);

            } // @ public double PosY

            /// <summary>
            /// Z position of the NPC
            /// </summary>
            public float PosZ(short id)
            {
                return GetNPCPosZ(_InstanceID, id);

            } // @ public double PosZ

            /// <summary>
            /// H position of the NPC
            /// </summary>
            public float PosH(short id)
            {
                return GetNPCPosH(_InstanceID, id);

            } // @ public double PosH

            /// <summary>
            /// Gets the position of the NPC
            /// </summary>
            public Position GetPosition(short id)
            {
                return new Position 
                           { 
                               X = GetNPCPosX(_InstanceID, id),
                               Y = GetNPCPosY(_InstanceID, id),
                               Z = GetNPCPosZ(_InstanceID, id),
                               H = GetNPCPosH(_InstanceID, id)
                           };

            } // @ public Position GetPosition(short index)

            /// <summary>
            /// NPC's current hit point percent
            /// </summary>
            public short HPPCurrent(short id)
            {
                return GetNPCHPP(_InstanceID, id);

            } // @ public short HPPCurrent

            /// <summary>
            /// NPC's status
            /// </summary>
            public Status Status(short id)
            {
                return GetNPCStatus(_InstanceID, id);

            } // @ public Status Status

            /// <summary>
            /// ID of the NPC's pet
            /// </summary>
            public int PetID(short id)
            {
                return GetNPCPetID(_InstanceID, id);

            } // @ public short PetID

            /// <summary>
            /// NPC's current TP
            /// </summary>
            public short TPCurrent(short id)
            {
                return GetNPCTP(_InstanceID, id);

            } // @ public short TP

            /// <summary>
            /// NPC's distance from player
            /// </summary>
            public double Distance(short id)
            {
                return GetNPCDistance(_InstanceID, id);

            } // @ public double Distance

            #endregion

        } // @ public class NPCTools
    } // @ public partial class FFACE
}
